/**
	星星节点
**/

var StarColorEnum = cc.Enum({
    1:new cc.hexToColor("#44F174"),//GREEN
    2:new cc.hexToColor("#F1D644"),//YELLOW
    3:new cc.hexToColor("#F144EA"),//PURPLE
    4:new cc.hexToColor("#D62F2F"),//RED
});

var StarMediator = cc.Class({
    extends: cc.Component,
    name: 'StarMediator',
    properties: {
        spriteFrameArrs:{
            default:[],
            type: cc.SpriteFrame
        },
        fallParticleNode:{
            default:null,
            type: cc.Node
        },
        selectSpNode:{
            default:null,
            type: cc.Node
        }
    },
    onLoad: function () {
        this.resetColor();
        // this.fallAction();
    },
    reuse:function(){
        this.setSelectSpEnable(false);
        this.resetColor();
        // this.fallAction();
    },
    setData:function(pointer){
        this.mainControllMediator = pointer;
    },
    //颜色重置
    resetColor:function(){
        var spSize = this.spriteFrameArrs.length;
        var i = Math.floor(Math.random() * spSize);
        // this.node.color = StarColorEnum[i];
        this.node.getComponent(cc.Sprite).spriteFrame = this.spriteFrameArrs[i];
        this.node.colorTag = i;
    },
    onBtnTouch:function(event){
        var touchNode = event.currentTarget;
        this.mainControllMediator.selectPointColor(touchNode);
    },
    blinkAction:function(cb){
        var action_1 = cc.blink(0.8,2);
        var action_2 = cc.callFunc(function(){
            cb();
        });
        this.node.runAction(cc.sequence(action_1,action_2));
    },
    fallAction:function(){
        var self = this;
        self.fallParticleNode.active = true;
        this.node.y -= 20;
        var action_1 = cc.moveBy(0.5,0,20);
        var action_2 = cc.callFunc(function(){
            self.fallParticleNode.active = false;
        });
        this.node.runAction(cc.sequence(action_1,action_2));
    },
    setSelectSpEnable:function(enable){
        this.selectSpNode.active = enable;
    }
});

module.exports = StarMediator;